<template>
  <div>
    <el-row>
      <el-col :span="24">
        <el-card>
          <div slot="header" class="clearfix">
            <span>填写假条</span>
          </div>
          <el-select v-model="form.leaveType" placeholder="请选择请假类型">
            <el-option
              v-for="item in leavetypeOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
          <div style="height: 20px"></div>
          <el-date-picker
            v-model="form.leavtTime"
            type="datetimerange"
            align="right"
            unlink-panels
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          >
          </el-date-picker>
          <div style="height: 20px"></div>
          <el-input
            type="textarea"
            placeholder="请输入内容"
            v-model="form.leaveContent"
            maxlength="100"
            show-word-limit
          >
          </el-input>
          <div style="height: 20px"></div>
          <div style="float: right">
            <el-button type="primary" @click="onapplication">提交</el-button>
            <div style="height: 20px"></div>
          </div>
        </el-card>
        <el-divider><i class="el-icon-loading"></i></el-divider>
        <el-card style="margin-top: 20px; margin-bottom: 5rem">
          <el-table
            :data="tableData"
            border
            :default-sort="{ prop: 'createtime', order: 'descending' }"
            style="width: 100%"
          >
            <el-table-column align="center" label="申请时间" sortable>
              <template slot-scope="scope">{{
                scope.row.createtime | date
              }}</template>
            </el-table-column>
            <el-table-column align="center" prop="leavetype" label="类型">
            </el-table-column>
            <el-table-column align="center" prop="reason" label="详细信息">
            </el-table-column>
            <el-table-column align="center" label="审核结果">
              <template slot-scope="scope">
                <el-tag :type="scope.row.state | type">{{
                  scope.row.state | state
                }}</el-tag>
              </template>
            </el-table-column>
          </el-table>
        </el-card>
      </el-col>
      <!--<div style="width: 100%;height: 70rem"></div>-->
    </el-row>
  </div>
</template>

<script>
import dayjs from 'dayjs'
export default {
  data () {
    return {
      tableData: [],
      leavetypeOptions: [{
        value: '请假',
        label: '请假'
      }, {
        value: '外出',
        label: '外出'
      }],
      form: {
        leaveContent: '',
        leaveType: '',
        leavtTime: ''
      },

    }
  },
  created () {
    this.getapplication()
  },
  filters: {
    date (time) {
      return dayjs(time).format('YYYY-MM-DD HH-mm')
    },
    state (type) {
      if (type == 0) {
        return '未审批'
      }
      if (type == 1) {
        return '审核不通过'
      }
      if (type == 2) {
        return '审核通过'
      }
    },

    type (type) {
      if (type == 0) {
        return ''
      }
      if (type == 1) {
        return 'danger'
      }
      if (type == 2) {
        return 'success'
      }
    }
  },
  methods: {
    /**获取我的请假单
    
     * */
    async getapplication () {
      const { data: result } = await this.$Axios.get('admin/getuserLeave')
      console.log(result)
      this.tableData = result
    },
    /**
     * 请假
     */
    async onapplication () {
      if (!this.form.leaveContent || !this.form.leaveType || !this.form.leavtTime) this.open3("请假信息不可以留空")
      else {
        const { data: result } = await this.$Axios.post('student/setLeave', this.form)
        if (result.code == 200) {
          this.$message.success('发送成功')
          this.getapplication()
        }
      }

    },
  }
}
</script>